//
//  LYQMineIntegralViewController.m
//  ZCProject
//
//  Created by Zheng on 16/12/6.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineIntegralViewController.h"

#import "LYQMineIntegralCell.h"
#import "LYQIntegralHeaderView.h"

@interface LYQMineIntegralViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) LYQIntegralHeaderView *headerView;

@property (nonatomic, strong) NSArray *iTitleNameArr; //我的积分下标题
@property (nonatomic, strong) NSArray *aTitleNameArr; //今日商情余量下标题
@property (nonatomic, strong) NSArray *number1Arr; //每日上限

@end

@implementation LYQMineIntegralViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"积分";
    
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    self.listTableView.scrollEnabled = NO;
    
    _iTitleNameArr = @[@"积分获取途径",@"每日登录",@"分享内容",@"发布观点/评论"];
    _aTitleNameArr = @[@"添加好友",@"回复资源咨询",@"回复需求申请",@"申请需求"];
    
    _number1Arr = @[@"每日上限",@"5",@"5",@"10"];
    
}

#pragma mark - tableview sourcedata
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LYQMineIntegralCellStyle cellStyle;
    NSString *identifier = @"";
    
    if (indexPath.section == 0) {
        cellStyle = LYQMineIntegralCellIntegralStyle;
        identifier = kLYQMineIntegralCell_ID;
    } else {
        cellStyle = LYQMineIntegralCellAllowanceStyle;
        identifier = kLYQMineAllowanceCell_ID;
    }
    
    LYQMineIntegralCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[LYQMineIntegralCell alloc] initWithCellStyle:cellStyle];
    }
    
    if (indexPath.section == 0) {
        cell.value1Lbl.text = _aTitleNameArr[indexPath.row];
        cell.value2Lbl.text = _number1Arr[indexPath.row];
        
        if (indexPath.row == 0) {
            cell.value1Lbl.textColor = kLYQBlack;
            cell.value2Lbl.textColor = kLYQBlack;
            cell.value3Lbl.textColor = kLYQBlack;
            cell.value3Lbl.text = @"今日成绩";
        } else {
            //TODO:填写数据
            cell.value3Lbl.textColor = RGB(252, 107, 74, 1);
            cell.value3Lbl.text = @"+ 5";
        }
    } else {
        
        cell.titleLbl.text = _iTitleNameArr[indexPath.row];
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"5/5"];
        [str addAttribute:NSForegroundColorAttributeName value:RGB(252, 107, 74, 1) range:NSMakeRange(0, 2)];
        
        cell.valueLbl.attributedText = str;
        
    }
    
    return cell;

}

#pragma mark - tableview delegate
#pragma mark 头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kWScale(50);
}

#pragma mark 自定义头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    _headerView = [[LYQIntegralHeaderView alloc] init];
    
    if (section == 0) {
        _headerView.titleLbl.text = @"我的积分";
        _headerView.instructionsBtn.hidden = NO;
    } else {
        _headerView.titleLbl.text = @"今日商情余量";
        _headerView.instructionsBtn.hidden = YES;
    }
    
    return _headerView;
}

#pragma mark 尾视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001f;
}

#pragma mark 单元格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kWScale(45);
}

#pragma mark 设置分割线偏移量
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
